Configuring: .NET Expression
Select a dataset to which you want to add a new field. Write a .NET expression that will give values to this field. This operation will modify the existing dataset by adding the new field.
For this operation to execute it is important to verify the script. This operation will only give the desired outputs, once all compiler errors given by the selected .NET language when verifying the script, are corrected.
Worked example: .NET expression
Steps to configure
-
Field expression: Add the new field and expression that will be used to give values to the new field.
-
Verify expression: Check to see if the script can compile.
-
Execution: The existing dataset will be modified to include the newly added field.
Step 1: Field expression
Define a new field name, select a data type, specify the timestamp, and choose the programming language.
-
Field name: Define a new field name
-
Data type: select the type of data for the new field from the drop down menu
-
Language: choose the language in which to create the expression
-
Timestamp: select whether to use local time or UTC time
-
Expression: Set the expression that will determine the values of the new field.
-
Limitations: Read more on limitations of the .NET script.
-
Current fields in the existing dataset will be listed in the window of fields.
-
Default:
-
-
Data type: double
-
Programming language: C#
-
Timestamp: UTC
-
-
Minimum configuration:
-
-
name for the new field
-
valid expression in the chosen programming language.
-
Expression:
The expression is executed for every row of the selected dataset. When a current field in the dataset is used in the expression, the value at each row of this field will be used to determine the new field’s value for that same row (e.g. if the expression for the new field is “Field1 + Field2”, where Field1 and Field2 are fields currently in the dataset, the new field’s values for each row will be the sum of the values of Field1 and Field2 for that row).
Input field:
All current fields in a dataset of types Double, Integer, String or DateTime can be accessed as input fields in this expression. These current fields, listed on the input field list, will have their appropriate values for that row.
The input fields are all declared in the .NET script as nullable types. These values can be read as either their respective types or a value of “null’. If a specific .NET method that you wish to call needs one of these script fields as a parameter, the value of the output field can be accessed with the “.Value” property (e.g. Math.Round(InputField1.Value) ).
Output field:
A single field can be created of types Double, Integer, String or DateTime. Setting a value in the script for the output field will add that value into the dataset for the current row's execute.
The output field is declared in the .NET script as a nullable type. This values can be read or written as their respective types or a value of “null’. If a specific .NET method that you wish to call needs this script field as a parameter, the value of the output field can be accessed with the “.Value” property (e.g. Math.Round(InputField1.Value) ).
Data Quality:
When defining the data quality within a data preparation operation, data quality is not explicitly set to GOOD or BAD. Rather the field value is set to bad quality by setting it to the value 'null' in C# or the value 'Nothing' in VB. In the script, these fields are nullable types.
Timestamp:
For input fields:
-
All input fields of DateTime type will have its time type set to the selected setting: either Local Time or UTC time.
-
The selected time type setting does not change the actual value of the timestamp field, merely the time type that the timestamp is being interpreted as when being used in the script.
For output fields:
-
Output fields of DateTime type that have an unspecified time type, will be interpreted as the selected time type setting, but always displayed to the user as Local Time.
-
Be aware that defining the time type setting by toggling between the UTC and Local Time buttons will change the timestamp value displayed when the output field’s time type was unspecified.
Namespaces:
The expression itself has all features provided by the chosen .NET language. Click here to see the included namespaces.
Step 2: Verify expression
No configuration changes are made on this page. It either shows that the script has compiled successfully, or lists the errors that occurred when compiling the expression. You have the option to click [Finish] if a valid expression was entered, or [Back] to modify the expression.
Step 3: Execute
The dataset will be modified to include the added field and the values as specified in the expression.
Related topics: